﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ReportDesignerServer.Dto
{
    /// <summary>
    /// 统一返回数据实体
    /// </summary>
    public class Rt
    {
        /// <summary>
        /// 结果
        /// </summary>
        public string code { get; set; } = "200";

        /// <summary>
        /// 结果相关msg
        /// </summary>
        public string msg { get; set; } = "";

        /// <summary>
        /// 数据
        /// </summary>
        public object? data { get; set; }

        /// <summary>
        /// 成功
        /// </summary>
        /// <returns></returns>
        public static Rt Success()
        {
            return new Rt() { code = "200", msg = "操作成功" };
        }

        /// <summary>
        /// 成功，添加实体
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public static Rt SuccessObj(object? o)
        {
            return new Rt() { code = "200", msg = "操作成功", data = o };
        }

        /// <summary>
        /// 报错
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static Rt Error(string msg = "出现错误")
        {
            return new Rt() { code = "200", msg = msg };
        }

        /// <summary>
        /// 失败
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static Rt Fail(string msg = "操作失败")
        {
            return new Rt() { code = "400", msg = msg };
        }
    }

}
